home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 February
/
EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso
/
earcd
/
midi
/
midifl12.lha
/
midifile.new
/
mfwrite_ex.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-27
|
2KB
|
76 lines
/*
* writing_example.c 4/30/89
*
*/
#include <stdio.h>
#include <ctype.h>
#include "midifile.h"
/* These lines are needed to use the library */
FILE *fp;
/* myputc : returns <int> with input variables:
* c:
*/
int myputc (char c)
{
return (putc (c, fp));
}
/* ------------------------------------------------------------------------ */
/*
* mywritetrack()
*
* Sample showing how to use the library routines to write out a track.
* Returns 1 if successful, and -1 if not. The track consists of
* a series of quarter notes from lowest to highest in pitch at
* constant velocity, each separted by a quarter-note rest.
*
*/
/* mywritetrack : returns <int> with input variables:
* track:
*/
int mywritetrack (int track)
{
int i;
char data[2];
mf_write_tempo ((long) 500000); /* 120 beats/per/second */
for (i = 1; i < 128; i++) {
data[0] = i; /* note number */
data[1] = 64; /* velocity */
if (!mf_write_midi_event (480, note_on, 1, data, 2))
return (-1);
if (!mf_write_midi_event (480, note_off, 1, data, 2))
return (-1);
}
return (1);
}
/* ------------------------------------------------------------------------ */
/* end of write_track() */
/* main : returns <int> with input variables:
* argc:
* argv:
*/
int main (
int argc,
char **argv)
{
if ((fp = fopen (argv[1], "w")) == 0L)
printf ("f1to0: unable to open file %s for writing.\n", argv[1]);
Mf_putc = myputc;
Mf_writetrack = mywritetrack;
/* write a single track */
mfwrite (0, 1, 480, fp);
}
/* ------------------------------------------------------------------------ */